#include <fstream>
#include "Hermite.h"
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;


int main()
{


  double n;
  double a[10] = {0,0,3,3,5,5,8,8,13,13};
  double b[10] = {0,0,225,225,383,383,623,623,993,993};
  double c[5] = {75,77,80,74,72};
  vector<double> x;
  vector<double> y;
  for (int i=0; i<10; i++)
    {
      x.push_back(a[i]);
      y.push_back(b[i]);
    }
  vector<double> yy;
  for (int i=0; i<5; i++)
    {
      yy.push_back(c[i]);
    }
 
 

 Hermite problem_d(x,y,yy);

 double t=10;
 double dis=0;
 n=x.size();
 for(int i=0;i<n;i++){
   dis=dis+pow(t,n-1-i)*problem_d.answer[i];
 }
  cout<<"the position: "<<dis<<endl;
  cout<<"the speed: "<<problem_d.diff(x,t)<<endl;

  ofstream p_D;
    p_D.open("p_D.txt", std::ios::out);
       if (!p_D.is_open())
        return 0;
            for(int i=0;i<x.size()-1;i++)
	      {
		p_D<< problem_d.answer[i]*(10-i-1) <<endl;
              }

	      p_D.close();
	      
  double tt;
  double limit=81;
  double speed_max=0;
  double count=0;
  double percent=0;
  for (tt=0;tt<=13;tt=tt+0.01)
    {
      if (problem_d.diff(x,tt)>limit)
	{
	  count=count+1;
	  if (problem_d.diff(x,tt)>speed_max)
	    speed_max=problem_d.diff(x,tt);
	}		    
    }
  percent=(count*100)/1300;
  if (count==0)
    cout<<"The car never exceeds the speed limit."<<endl;
  else
    cout<<"The car exceeds the speed limit in "<<percent<<"%"<<" of the time in [0,13] ."<<endl;
  cout<<"The maximum speed of the car is "<<speed_max<<" ."<<endl;
	      
	      
}
